/*
 * @Author: yangzonglong
 * @Date: 2021-03-01 13:18:46
 * @version: v1.0.0
 * @Descripttion: Switch 组件
 * @LastEditors: yangzonglong
 * @LastEditTime: 2021-04-07 17:22:43
 * @Auditor: 
 */
import React from 'react';
import { Form, Switch } from 'antd';
import { SwitchProps as AntdSwitchProps } from 'antd/lib/switch';
import { FormItemProps } from '../../components/components/InputFormItemController';
import useQueryControlWrap from '../../hooks/useQueryControlWrap';
import { CanvasItemProps } from './../../interface';

export interface SwitchProps extends CanvasItemProps {
  switchProps?: AntdSwitchProps;
  formItemProps?: FormItemProps;
  disabled?: boolean;
}

const App = (props: SwitchProps) => {

  const { disabled, switchProps, formItemProps, domComplete, ...canvasProps } = props;
  useQueryControlWrap(canvasProps.id, formItemProps?.name, domComplete);

  const label = localStorage.i18nextLng === 'en' ? formItemProps?.labelEn : formItemProps?.label;

  return (
    <Form.Item {...canvasProps} {...props.formItemProps} valuePropName="checked" label={label}>
      <Switch {...props.switchProps} disabled={disabled || formItemProps?.disabled} />
    </Form.Item>
  );
};

export default App;